package cn.jiemusic.service.impl;

import cn.jiemusic.domain.po.User;
import cn.jiemusic.domain.po.UserLike;
import cn.jiemusic.mapper.UserMapper;
import cn.jiemusic.service.UserLikeService;
import cn.jiemusic.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;

import java.util.ArrayList;

@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserLikeService userLikeService;

    @Override
    public void reg(User user) {
        //对密码进行加密
        String password = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
        user.setPassword(password);
        save(user);
        UserLike userLike = new UserLike();

        userLike.setId(user.getId());
        userLike.setLikeSong(new ArrayList<>());
        userLikeService.save(userLike);
    }
}
